/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * tabla.java
 *
 * Created on 19-feb-2011, 16:42:25
 */

package jfreefall;

import java.awt.Cursor;
import java.text.DecimalFormat;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableModel;
import java.util.*;
import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;
import java.awt.image.BufferedImage;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import org.jfree.ui.RefineryUtilities;


/**
 *
 * @author joshi
 */
public class tabla extends javax.swing.JFrame {
    private static Vector tableData;
    private static Vector<String> tableHeaders;
    private Vector<Object> oneRow;

    private DecimalFormat df = new DecimalFormat("0.000");

    int n=0;
    double scx=0, scy=0, scxy=0;
    double xtotal =0, ytotal =0, xy=0, xytotal=0, sumx2=0, sumy2=0;
    double b1=0, b0=0;
    double det=0;
    double num=0.0;
    double x=0.0, y=0.0;

    double yprom = 0, xprom=0;
    double dtotal = 0, SCT = 0, dexplicada = 0, SCR = 0, dnexplicada = 0, SCE = 0, y0=0;
    double SSCT = 0, SSCR = 0, SSCE = 0;

    double r1=0, r2=0;

    double CME=0, sb1=0, se=0, tc=0, tt=0,c=0 , tcalc=0;
    double significancia=0;

    double ini=0, fin=0;

    public static LinkedList<nodo> lista;

    /** Creates new form tabla */
    public tabla() {
        initComponents();
        jGrafico.setVisible(false);
        setIconImage(new ImageIcon(getClass().getResource("/img/labs.png")).getImage());
         this.setLocationRelativeTo(null);
        cargar_modelo();
        cargar_datos();
        validez();
        validez2();
    }

    public static void cargar_modelo() {
        tableHeaders = new Vector<String>();
        tableData = new Vector();
        tableHeaders.add("Tiempo");
        tableHeaders.add("x");
        tableHeaders.add("y");
        tableHeaders.add("x^2");
        tableHeaders.add("y^2");
        tableHeaders.add("xy");
        tableHeaders.add("Dev-Total");
        tableHeaders.add("SCT");
        tableHeaders.add("y^");
        tableHeaders.add("Dev-Exp.");
        tableHeaders.add("SCR");
        tableHeaders.add("Dev No Exp.");
        tableHeaders.add("SCE");
        


        set_modelo();
    }

    
    public static void set_modelo(){
         tabla.JTabla.setModel(new DefaultTableModel(tableData, tableHeaders));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        JTabla = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        JSCX = new javax.swing.JLabel();
        JSCY = new javax.swing.JLabel();
        JSCXY = new javax.swing.JLabel();
        JB1 = new javax.swing.JLabel();
        JBO = new javax.swing.JLabel();
        JR1 = new javax.swing.JLabel();
        JR2 = new javax.swing.JLabel();
        JRR = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        JSCE = new javax.swing.JLabel();
        JCME = new javax.swing.JLabel();
        JSE = new javax.swing.JLabel();
        JTC = new javax.swing.JLabel();
        JSB1 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        JHIPO = new javax.swing.JLabel();
        JHIPO1 = new javax.swing.JLabel();
        JGrados = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jsig = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        JSIG = new javax.swing.JLabel();
        JB22 = new javax.swing.JLabel();
        JB23 = new javax.swing.JLabel();
        jint = new javax.swing.JLabel();
        jGrafico = new javax.swing.JButton();
        jhipo = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jcon1 = new javax.swing.JLabel();
        jcon2 = new javax.swing.JLabel();
        jcon3 = new javax.swing.JLabel();
        jcon4 = new javax.swing.JLabel();
        jcon5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jmodelo = new javax.swing.JLabel();
        jmodel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jdeterminacion = new javax.swing.JLabel();

        setBounds(new java.awt.Rectangle(0, 0, 689, 550));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jSplitPane1.setDividerLocation(550);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        JTabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(JTabla);

        jTabbedPane1.addTab("Datos", jScrollPane1);

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        JSCX.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/scx.png"))); // NOI18N

        JSCY.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/SCy.png"))); // NOI18N

        JSCXY.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/scxy.png"))); // NOI18N

        JB1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/b1.png"))); // NOI18N

        JBO.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/b0.png"))); // NOI18N

        JR1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/r1.png"))); // NOI18N

        JR2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/r2.png"))); // NOI18N

        JRR.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/r22.png"))); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JSCX)
                    .addComponent(JSCY)
                    .addComponent(JSCXY)
                    .addComponent(JB1)
                    .addComponent(JRR)
                    .addComponent(JBO)
                    .addComponent(JR1)
                    .addComponent(JR2))
                .addContainerGap(501, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(JSCX)
                .addGap(18, 18, 18)
                .addComponent(JSCY)
                .addGap(26, 26, 26)
                .addComponent(JSCXY)
                .addGap(18, 18, 18)
                .addComponent(JB1)
                .addGap(18, 18, 18)
                .addComponent(JBO)
                .addGap(18, 18, 18)
                .addComponent(JR1)
                .addGap(26, 26, 26)
                .addComponent(JR2)
                .addGap(18, 18, 18)
                .addComponent(JRR)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Calculos", jPanel3);

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        JSCE.setBackground(new java.awt.Color(255, 255, 255));
        JSCE.setText("SCE");

        JCME.setBackground(new java.awt.Color(255, 255, 255));
        JCME.setText("CME");

        JSE.setBackground(new java.awt.Color(255, 255, 255));
        JSE.setText("Se");

        JTC.setBackground(new java.awt.Color(255, 255, 255));
        JTC.setText("Se");

        JSB1.setBackground(new java.awt.Color(255, 255, 255));
        JSB1.setText("CME");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JTC)
                    .addComponent(JSB1)
                    .addComponent(JSE)
                    .addComponent(JCME)
                    .addComponent(JSCE))
                .addContainerGap(642, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(JSCE)
                .addGap(35, 35, 35)
                .addComponent(JCME)
                .addGap(30, 30, 30)
                .addComponent(JSE)
                .addGap(31, 31, 31)
                .addComponent(JSB1)
                .addGap(28, 28, 28)
                .addComponent(JTC)
                .addContainerGap(382, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Prueba de validez (1)", jPanel4);

        jPanel5.setBackground(new java.awt.Color(255, 255, 255));

        JHIPO.setText("JHIPO");

        JHIPO1.setText("JHIPO");

        JGrados.setText("JHIPO");

        jLabel2.setText("Significancia ");

        jButton1.setText("Calcular");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        JSIG.setText("tt");

        JB22.setText("B1");

        jGrafico.setText("Ver Gráfico");
        jGrafico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jGraficoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jhipo)
                    .addComponent(jGrafico)
                    .addComponent(jint)
                    .addComponent(JB23)
                    .addComponent(JB22)
                    .addComponent(JSIG)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jsig, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addComponent(JGrados)
                    .addComponent(JHIPO1)
                    .addComponent(JHIPO))
                .addContainerGap(459, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(JHIPO)
                .addGap(18, 18, 18)
                .addComponent(JHIPO1)
                .addGap(18, 18, 18)
                .addComponent(JGrados)
                .addGap(18, 18, 18)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jsig, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addComponent(JSIG)
                .addGap(18, 18, 18)
                .addComponent(JB22)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(JB23)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jint)
                .addGap(18, 18, 18)
                .addComponent(jGrafico)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jhipo)
                .addContainerGap(324, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Prueba de validez (2)", jPanel5);

        jPanel6.setBackground(new java.awt.Color(255, 255, 255));

        jcon1.setText("c1");

        jcon2.setText("c2");

        jcon3.setText("c3");

        jcon4.setText("c4");

        jcon5.setText("c4");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jcon1)
                    .addComponent(jcon2)
                    .addComponent(jcon3)
                    .addComponent(jcon4)
                    .addComponent(jcon5))
                .addContainerGap(661, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jcon1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jcon2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcon3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jcon4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jcon5)
                .addContainerGap(489, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Conclusiones", jPanel6);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 687, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 632, Short.MAX_VALUE)
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("Datos");

        jSplitPane1.setLeftComponent(jPanel1);

        jmodelo.setText("Modelo obtenido:");

        jLabel1.setText("Coeficiente de determinación :");

        jdeterminacion.setText("jLabel2");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jmodelo)
                        .addGap(10, 10, 10)
                        .addComponent(jmodel, javax.swing.GroupLayout.PREFERRED_SIZE, 552, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jdeterminacion, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jmodelo)
                    .addComponent(jmodel, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jdeterminacion))
                .addGap(19, 19, 19))
        );

        jSplitPane1.setRightComponent(jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 689, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 688, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        jfreefall.pool.topen = false;
    }//GEN-LAST:event_formWindowClosing

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        significancia();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jGraficoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jGraficoActionPerformed
        // TODO add your handling code here:
        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        graficaT gt = new graficaT("Intevalo de confianza", tc, tt,c,n-2);
        gt.pack();
        RefineryUtilities.centerFrameOnScreen(gt);
        gt.setVisible(true);
        this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }//GEN-LAST:event_jGraficoActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new tabla().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel JB1;
    private javax.swing.JLabel JB22;
    private javax.swing.JLabel JB23;
    private javax.swing.JLabel JBO;
    private javax.swing.JLabel JCME;
    private javax.swing.JLabel JGrados;
    private javax.swing.JLabel JHIPO;
    private javax.swing.JLabel JHIPO1;
    private javax.swing.JLabel JR1;
    private javax.swing.JLabel JR2;
    private javax.swing.JLabel JRR;
    private javax.swing.JLabel JSB1;
    private javax.swing.JLabel JSCE;
    private javax.swing.JLabel JSCX;
    private javax.swing.JLabel JSCXY;
    private javax.swing.JLabel JSCY;
    private javax.swing.JLabel JSE;
    private javax.swing.JLabel JSIG;
    private javax.swing.JLabel JTC;
    public static javax.swing.JTable JTabla;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jGrafico;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel jcon1;
    private javax.swing.JLabel jcon2;
    private javax.swing.JLabel jcon3;
    private javax.swing.JLabel jcon4;
    private javax.swing.JLabel jcon5;
    public static javax.swing.JLabel jdeterminacion;
    private javax.swing.JLabel jhipo;
    private javax.swing.JLabel jint;
    private javax.swing.JLabel jmodel;
    public static javax.swing.JLabel jmodelo;
    private javax.swing.JTextField jsig;
    // End of variables declaration//GEN-END:variables

    private void cargar_datos() {
        
        int time = (int) Math.sqrt(pool.h/(.5*pool.gravedad));
       
        
        for (int i=0; i<=time; i++){

            for (int s=0; s<100; s+=10){
          
            num = s;
            x =calcula_x(i+(num/100));
            y = calcula_y(i+(num/100));
            
            if (i==1 && s==10){
                pool.x0 = x;
                pool.y0 = y;
            }

            if (y>0){
         
                    xytotal +=x*y;
                    xtotal +=x;
                    ytotal +=y;
                    sumy2+=y*y;
                    sumx2+=x*x;
                    n++;
                    pool.yn = y;
                    pool.xn = x;

                    pool.ex.add(i+(num/100),x,y, x*x, y*y, x*y, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);

            }else{
                break;
            }

            }
        }
        

        
        System.out.println(xytotal +" "+xtotal+" "+ytotal+" "+sumy2+" "+sumx2);
        //System.out.println(n);
       // System.out.println(pool.x0+" "+pool.y0+" "+pool.xn+" "+pool.yn);
        calcular();

        
        
        lista = pool.ex.getlista();
        recorrer();

        calcular2();
    }

    private double calcula_x(double i){
        double valor = pool.velocidad *i;
        return valor;
    }

    private double calcula_y(double i){
        double valor = valor = pool.h-pool.gravedad*0.5*(i*i);
        return valor;
    }

    private void calcular() {
        scx = sumx2-(xtotal*xtotal/n);
        scy = sumy2-(ytotal*ytotal/n);
        scxy = xytotal-(xtotal*ytotal/n);
        b1 = scxy/scx;
        b0 = (ytotal/n)-(b1*(xtotal/n));
        det =(scxy*scxy)/(scx*scy);



        System.out.println(b1);
        System.out.println(b0);

        pool.b0 = b0;
        pool.b1 = b1;
        pool.det = det;

        String mat;
        if (b0>0){
       // jmodel.setText("y^="+df.format(b1)+"x+"+df.format(b0));
        mat = "\\hat{y} = "+b1+"x+"+b0;
        jmodel.setIcon(get_latex(mat));
        }
        else{
        //jmodel.setText("y^="+df.format(b1)+"x"+df.format(b0));
            mat = "\\hat{y} = "+b1+"x"+b0;
        jmodel.setIcon(get_latex(mat));
        }

        //this.jdeterminacion.setText(df.format(det));
        mat = "r^2 = "+det;
        jdeterminacion.setIcon(get_latex(mat));

    }

    private void recorrer() {

        int size = lista.size();
        xprom = xtotal/size;
        yprom = ytotal/size;



        for (int i=0; i<lista.size(); i++){
             oneRow = new Vector<Object>();
             oneRow.add(lista.get(i).T);
             oneRow.add(lista.get(i).x);
             oneRow.add(lista.get(i).y);
             oneRow.add(lista.get(i).x2);
             oneRow.add(lista.get(i).y2);
             oneRow.add(lista.get(i).xy);
             dtotal = lista.get(i).y - yprom;
             oneRow.add(dtotal);
                SCT = dtotal*dtotal;
                SSCT +=SCT;
             oneRow.add(SCT);
                y0 = lista.get(i).x*b1 + b0;
             oneRow.add(y0);
                dexplicada = y0-yprom;
             oneRow.add(dexplicada);
                SCR = dexplicada*dexplicada;
                SSCR +=SCR;
             oneRow.add(SCR);
                dnexplicada = lista.get(i).y-y0;
             oneRow.add(dnexplicada);
                SCE = dnexplicada*dnexplicada;
                SSCE +=SCE;
             oneRow.add(SCE);
             tableData.add(oneRow);
        }

        set_modelo();

    }

    private void calcular2() {
        String math;
        math = "SCx = \\sum x_i^2-\\frac{{\\sum x_i }^2}{n}= "+sumx2+" - \\frac{"+xtotal*xtotal+"}{"+n+"} = "+scx+" ";
        JSCX.setIcon(get_latex(math));

        math = "SCy = \\sum y_i^2-\\frac{{\\sum y_i }^2}{n}= "+sumy2+" - \\frac{"+ytotal*ytotal+"}{"+n+"} = "+scy+" ";
        JSCY.setIcon(get_latex(math));

        math = "SCxy = xy - \\frac{\\sum x \\sum y }{n}= "+xytotal+" - \\frac{"+xtotal*ytotal+"}{"+n+"} = "+scxy+" ";
        JSCXY.setIcon(get_latex(math));

        r1=scxy/Math.sqrt(scx*scy);
        r2 = Math.sqrt(SSCR/SSCT);

        math = "\\hat{\\beta_1} = \\frac {SCxy}{SCx} = \\frac {"+scxy+"}{"+scx+"} = "+b1;
        JB1.setIcon(get_latex(math));

        math = "\\hat{\\beta_0} = \\bar{y}-\\beta_1\\bar{x} = "+yprom+"-"+b1*xprom+" = "+b0;
        JBO.setIcon(get_latex(math));

        
        math = "r_1= \\frac{SCxy}{\\sqrt{SCx SCy}} = \\frac{"+scxy+"}{\\sqrt{"+scx*scy+"}}= "+r1;
        JR1.setIcon(get_latex(math));

        math = "r_2= \\frac{SCR}{SCT} = \\frac{"+SCR+"}{"+SCT+"} = "+r2;
        JR2.setIcon(get_latex(math));

        math = "r^2= \\frac{SCxy^2}{SCx SCy} = \\frac{"+scxy*scxy+"}{"+scx*scy+"} = "+det;
        JRR.setIcon(get_latex(math));


//       jscx1.setText(df.format(sumx2));
//       jscx2.setText(df.format(xprom*xprom));
//       jscx3.setText(df.format(n));
//       jscx4.setText(df.format(scx));
//
//       jscy1.setText(df.format(sumy2));
//       jscy2.setText(df.format(yprom*yprom));
//       jscy3.setText(df.format(n));
//       jscy4.setText(df.format(scy));
//
//       jscxy1.setText(df.format(xytotal));
//       jscxy2.setText(df.format(xtotal*ytotal));
//       jscxy3.setText(df.format(n));
//       jscxy4.setText(df.format(scxy));
//
//       jb11.setText(df.format(scxy));
//       jb12.setText(df.format(scx));
//       jb13.setText(df.format(b1));
//
//       jb01.setText(df.format(yprom));
//       jb02.setText(df.format(b1*xprom));
//       jb03.setText(df.format(b0));
//
//       r1=scxy/Math.sqrt(scx*scy);
//       jr1.setText(df.format(r1));
//
//       r2 = Math.sqrt(SSCR/SSCT);
//       jr2.setText(df.format(r2));
//
//       jr22.setText(df.format(det));
    }

    private void validez() {
        String math;
        math= "SCE = SCy -  \\frac {SCxy^2} {SCx} = "+scy+" -  \\frac {"+scxy*scxy+"} {"+scx+"} = "+SCE;
        JSCE.setIcon(get_latex(math));

        CME =SCE/(n-2);
        math = "CME = \\frac {SCE} {n-2} =  \\frac {"+SCE+"} {"+(n-2)+"} = "+CME;
        JCME.setIcon(get_latex(math));

  
        se = Math.sqrt(CME);
        math = "Se = \\sqrt{CME} = \\sqrt{"+CME+"}   = "+se;
        JSE.setIcon(get_latex(math));

        sb1 = se / Math.sqrt(scx);
        math = "Sb_1 = \\frac{se} {\\sqrt{SCx} }= \\frac{"+se+"} {\\sqrt{"+scx+"}} = "+sb1;
        JSB1.setIcon(get_latex(math));

        tc = b1 / sb1;
        math = "t_c = \\frac{b_1-\\beta_1} {Sb_1} = \\frac{"+b1+"- 0} {"+sb1+"}  = "+tc;
        JTC.setIcon(get_latex(math));

    }

    private TeXIcon get_latex(String math){
        TeXFormula fomule = new TeXFormula(math);
        TeXIcon ti = fomule.createTeXIcon(
        TeXConstants.STYLE_DISPLAY, 16);
        BufferedImage b = new BufferedImage(ti.getIconWidth(), ti
            .getIconHeight(), BufferedImage.TYPE_INT_RGB);
        ti.paintIcon(new JLabel(), b.getGraphics(), 0, 0);

        return ti;
    }

    private void validez2() {
        String math;
        math = "H_0: \\beta_1 = 0";
        JHIPO.setIcon(get_latex(math));
        math = "H_a: \\beta_1 \\neq 0";
        JHIPO1.setIcon(get_latex(math));
        math = " n - 2 = "+n+"-2 = "+(n-2);
        JGrados.setIcon(get_latex(math));
        
        math = " t_t(\\infty/2, n-2) =";
        JSIG.setIcon(get_latex(math));

        math = "\\beta_1 = b_1 \\pm t_t(Sb_1)";
        JB22.setIcon(get_latex(math));



    }

    private void significancia() {

        double si= java.lang.Double.valueOf(jsig.getText());
        c =si;

        String math;
        if (si>0 && si<1){

        
        si=si/2;
        double grado = cern.jet.stat.Probability.studentTInverse(si,(n-2));
        tt=grado;
        math = " t_t(\\infty/2, n-2) = t_t("+si+", "+(n-2)+") = "+grado;
        JSIG.setIcon(get_latex(math));

        math = "\\beta_1 = "+b1+" \\pm "+grado+"("+sb1+")";
        JB23.setIcon(get_latex(math));

        ini = b1 + (grado*sb1);
        fin = b1 - (grado*sb1);

            if (ini > fin){
                math = "["+fin+","+ini+"]";
                jcon4.setText("<html><body> El Intervalo de confianza donde se encuentra el valor real de B1 esta dado por ["+fin+","+ini+ "]. </body></html>");
            }
            else{
                math = "["+ini+","+fin+"]";
                jcon4.setText("<html><body> El Intervalo de confianza donde se encuentra el valor real de B1 esta dado por ["+ini+","+fin+ "]. </body></html>");
            }
            jint.setIcon(get_latex(math));
            jGrafico.setVisible(true);

            //primera conclusión
              if (tc>tt || tc<tt*-1){
                math = " Se \\ rechaza \\ la \\ hipotesis \\ nula \\ H_0: \\beta_1 = 0 \\ y \\ " +
                        "se \\ acepta \\ la \\ hipotesis  \\ alternativa  H_a: \\beta_1  \\neq 0 ";
               this.jhipo .setIcon(get_latex(math));
              }
              else{
                math = " Se \\ acepta \\ la \\ hipotesis \\ nula \\ H_0: \\beta_1 = 0 \\ y \\ " +
                        "se \\ rechaza \\ la \\ hipotesis  \\ alternativa  H_a: \\beta_1  \\neq 0 ";
                jhipo.setIcon(get_latex(math));
              }

              conclusiones();
        }
        else{
            JOptionPane.showMessageDialog(null, "debe de ingresar un " +
                    "valor entre [0.1,0.99]", "Error de intervalo", JOptionPane.INFORMATION_MESSAGE);
        }


    }

    private void conclusiones() {
     String math = "";

      math = "<html><body> De los datos anteriores dado el coeficiente de determinación r2  propio de la variación de este conjunto de valores de la ecuación del tipo y = b1x+b0, Podemos concluir que el "+ r2*100 +"% de la variación es atribuible a la relación lineal aproximada entre la variable Y y la variable X </body></html>";
      this.jcon1.setText(math);

      if (Math.abs(r1)>.6){
      math = "<html><body> Decimos que existe un alto grado de correlación dado que el valor de r "+Math.abs(r1)+" se encuentra en el intervalo [0.6,1] </body></html>";
      this.jcon2.setText(math);

      }
      else{
      math = "<html><body> Decimos que existe un  grado de correlación  casi nulo dado que el valor de r "+Math.abs(r1)+" se encuentra en el intervalo [0.1,0.59] </body></html>";
      this.jcon2.setText(math);
      }

     int val = n-2;
       if (tc>tt || tc<tt*-1){
                math = "<html><body> Se ha rechazado la hipotesis nula dado que el valor de tc: "+tc+", se encuentra en el intervalor de  Tt +/- "+tt+" utilizando un intervalo de confianza de "+c+" y "+val+" grados de libertad." +
                        "Advertencia no quiere decir que el modelo sea bueno pero existe algún grado de correlación</body></html>";
               this.jcon3.setText(math);
              }
              else{
                math = "<html><body> Se ha Aceptado la hipotesis nula dado que el valor de tc: "+tc+", se encuentra en el intervalor de  Tt +/- "+tt+" utilizando un intervalo de confianza de "+c+" y "+val+" grados de libertad." +
                        "Es posible que el modelo no tenga ningún grado de correlación o un problema de multicolinealidad </body></html>";
                jcon3.setText(math);
              }

     math = "<html><body> El error de estandar de estimación, mide la variabilidad de los valores de Y con respecto a la volaores de la recta, por lo cual " +
    "el valor de Se = "+this.se+" nos dice que el error del modelo esta dado en "+this.se+" unidades." ;
     jcon5.setText(math);

    }

}
